/*
* @Author: Iuzuan
* @Date:   2017-12-13 14:17:22
* @Last Modified by:   Iuzuan
* @Last Modified time: 2017-12-14 17:14:34
*/
$(function(){

var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
var result = [];
var ranNum = arr.length;
for (var i = 0; i < ranNum; i++) {
var ran = Math.floor(Math.random() * arr.length);
result.push(arr.splice(ran, 1)[0]);
// console.log(result[result.length-1])
};
// console.log(result)
var idx = result.length

function ChoiceCard (){
	var card = result[idx-1]
	idx--
	// console.log(card)
	return  card
}

function audioPlay (url){
	$("audio").attr("src", url)
	$("audio")[0].play();
}

// 翻牌
$(".cardList li.prizeCard").on('click', function(){
	var liIdx = $(".cardList li.prizeCard").index(this)
	console.log(this)
	if(idx != 0 && $(this).hasClass('active') == false) {
		if (liIdx == 2) {
			audioPlay("media/award-big.mp3")
		}else {
			audioPlay("media/award-nomal.mp3")
		};
		$(this).addClass('active')
		$(this).css({
			background: 'url(img/openBox-' + ChoiceCard() + '.png) no-repeat center/6.6rem 6.6rem'
		});
		$(".cardList li.prizeCard:nth-child(" + (liIdx+1) + ") .prizeBg").addClass('active')
	}
	console.log(liIdx)
	var windowHeight = $(window).height()
	if (liIdx == 0) {
		scrollHeight =  0
	}else {
		scrollHeight = windowHeight*(liIdx)/2
	};
	$('.cardList').animate({scrollTop: scrollHeight},500);
})

// 开启宝箱
$('.treasureBox').on('click', function(){
	audioPlay("media/openbox.mp3")
	$(this).addClass('active')
	var boxTimer = setTimeout(function(){
		$(".cardList").fadeIn(2000, function() {
		});
		$('.treasureBox .box-content').fadeOut(1000);
	}, 1000)
})

// 全部领取
$(".receive").on("click", function(){
	audioPlay("media/Receive-all.mp3")
})



})

